package com.suse.service.view.edu.service.impl;

import com.suse.common.config.response.R;
import com.suse.service.view.edu.model.entity.Course;
import com.suse.service.view.edu.model.entity.Teacher;
import com.suse.service.view.edu.mapper.TeacherMapper;
import com.suse.service.view.edu.service.CourseService;
import com.suse.service.view.edu.service.TeacherService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 讲师 服务实现类
 * </p>
 *
 * @author 辜玉彬
 * @since 2022-08-16
 */
@Service
public class TeacherServiceImpl extends ServiceImpl<TeacherMapper, Teacher> implements TeacherService {

    @Resource
    private CourseService courseService;

    @Override
    public R getTeacherInfoAndCourseById(String id) {
        Teacher teacher = lambdaQuery()
                .select(Teacher::getId,
                        Teacher::getName,
                        Teacher::getAvatar,
                        Teacher::getCareer,
                        Teacher::getIntro,
                        Teacher::getLevel)
                .eq(Teacher::getId,id)
                .one();
        List<Course> courseList = courseService.lambdaQuery()
                .eq(Course::getTeacherId, id)
                .list();
        return R.put("teacher",teacher).put("courseList",courseList).success();
    }

    @Override
    public R getTeacherList() {
        List<Teacher> teacherList = lambdaQuery()
                .select(Teacher::getId,
                        Teacher::getName,
                        Teacher::getAvatar,
                        Teacher::getCareer,
                        Teacher::getIntro,
                        Teacher::getLevel)
                .list();
        return R.success(teacherList);
    }

    @Override
    public List<Teacher> getRecommendTeacherList() {
        return lambdaQuery()
                .orderByDesc(Teacher::getSort)
                .last("limit 4")
                .list();
    }

}
